require('../../assets/css/index.js')
require('../../assets/fonts/font/iconfont.css')
require('../../assets/lib/swiper/swiper-bundle.css')
let Swiper = require('../../assets/lib/swiper/swiper-bundle.js')
require('../../utils/local.js')
let https = require('../../utils/https.js')

// 引入公共js
let dom = require('../../utils/dom.js')
const local = require('../../utils/local.js')
const { set } = require('../../utils/local.js')
//引入当前页面的less文件
require('./course.less')
// 当前页面js
dom.isLogin();

dom.ready(function(){
    dom.bMenu('sports')
    dom.tMenu('course')
    function getCourseList(){
        https.get('/api/train/courseList',{},function(res){
            if(res.errno==0){
            // 方式一详情页获取参数   
                res.data.map((v,i)=>{
                    if(i==0){
                        local.set("rec",res.data)

                        // <a href="courseDetails.html?${v.courseId}">
                        dom.getEle('#newCourse').innerHTML+=`
                        <div class="itmes rel ">
                        <img src="${https.hostUrl+v.imgurl}" alt="" id="${v.courseId}">
                        <div class="title abs">
                            <h4>${v.name}</h4>
                            <p>${v.desc}</p>
                        </div>
                       
                    </div>
                   
                `
                    }else{
                        dom.getEle('#courseList').innerHTML+=`
                       <div class="itmes rel ">
                        <img src="${https.hostUrl+v.imgurl}" alt="" id="${v.courseId}">
                        <div class="title abs">
                            <h4>${v.name}</h4>
                            <p>${v.desc}</p>
                        </div>
              
                    </div>
                    
                `
                    }
                })
            }
            
        })
        
    };
    getCourseList();
    // 方式二绑定点击事件获取标签上id
        dom.getEle("#courseList").addEventListener("click",function(e){
            if(e.target.nodeName=="IMG"){
                console.log(e.target.id);
                console.log(e.target.getAttribute('id'));
                window.location.href='courseDetails.html?'+e.target.id;
            }
        })
        dom.getEle("#newCourse").addEventListener("click",function(e){
            if(e.target.nodeName=="IMG"){
                console.log(e.target.id);
                console.log(e.target.getAttribute('id'));
                window.location.href='courseDetails.html?'+e.target.id;
            }
        })
        // 方式三 本地存储
        // dom.getEle("#courseList").addEventListener("click",function(e){
        //         if(e.target.nodeName=="IMG"){
        //             // 先存
        // local.set('courseId0')
        //     //         console.log(e.target.id);
        //     //         console.log(e.target.getAttribute('id'));
        //     //         window.location.href='courseDetails.html?'+e.target.id
        //     //     }
        //     })
   
})